const mongoose = require("mongoose");
const moment = require('moment');
const Schema = mongoose.Schema;

const BaseSchema = {
  carNumber: String,
  carBrand: String,
  carModel: String,
  carYear: String,
  carMileage: String,
  carPrice: String,
  locked: String,
  handleBy: String,
  carUrl: String,
  carStatus: String,
  createTime: String,
  updateTime: String,
  stationId: String,
}
const TimeSchema = {
  createdAt: 'createTime',
  updatedAt: 'updateTime',
  currentTime: () => moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
}
/**
 * 车辆主数据
 */
const carMain = new Schema({
  ...BaseSchema,
  hireName: String,
  hireIdCard: String,
  hirePhoneNum: String,
  hireStartDateTime: String,
  hireEndDateTime: String,
  returnName: String,
  returnIdCard: String,
  returnPhoneNum: String,
  returnTime: String,
}, {
  timestamps: TimeSchema
})

/**
 * 车辆主数据
 */
const readyRecord = new Schema({
  ...BaseSchema,
  readyTime: String,
  handleBy: String
}, {
  timestamps: TimeSchema
})


// 车辆出租记录表
const hireRecord = new Schema({
  ...BaseSchema,
  hireName: String,
  hireIdCard: String,
  hirePhoneNum: String,
  hireStartDateTime: String,
  hireEndDateTime: String,
  handleBy: String
}, {
  timestamps: TimeSchema
})

// 车辆还车记录表
const returnRecord = new Schema({
  ...BaseSchema,
  returnName: String,
  returnIdCard: String,
  returnPhoneNum: String,
}, {
  timestamps: TimeSchema
})

// 待结算记录表
// const carOrder = new Scchema({
//   carNumber: String,
//   carBrand: String,
//   carModel: String,
//   carPrice: String,
//   orderStatus: String,

//   createTime: String,
//   updateTime: String,
//   handleBy: String
// }, {
//   timestamps: {
//     createdAt: 'createTime',
//     updatedAt: 'updateTime',
//     currentTime: () => moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
//   }
// })

const CarMains = mongoose.model("car_mains", carMain) // 主数据
const CarWaitReadys = mongoose.model("car_wait_readys", carMain) // 待整备
const CarReadys = mongoose.model("car_readys", readyRecord) // 待出租
const CarHires = mongoose.model("car_hires", hireRecord) // 已出租
const CarReturns = mongoose.model("car_returns", returnRecord) // 已还车

module.exports = {
  CarMains,
  CarWaitReadys,
  CarReadys,
  CarHires,
  CarReturns
}